package com.kinghunt.misp.common.enums.userx;

import lombok.Getter;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * 权限类型枚举
 *
 * @author jiangtao
 * @date 2020-01-30 20:36.
 */
public enum PermissionTypeEnum {
    /**
     * 普通权限
     */
    COMMON(0, "普通"),
    /**
     * 菜单权限
     */
    MENU(1, "菜单");

    @Getter
    private Integer type;
    @Getter
    private String desc;

    PermissionTypeEnum(Integer type, String desc) {
        this.type = type;
        this.desc = desc;
    }

    private final static Map<Integer, PermissionTypeEnum> map = new HashMap<>(8);
    static {
        for (PermissionTypeEnum e : PermissionTypeEnum.values()) {
            map.put(e.getType(), e);
        }
    }

    public static PermissionTypeEnum getByType(Integer type) {
        if (Objects.isNull(type)) {
            return null;
        }
        return map.get(type);
    }
}
